﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Masters/Basic.Master" AutoEventWireup="true" CodeBehind="CompanyInfoList.aspx.cs" Inherits="PMS.UI.BD.CompanyInfoList" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <script type="text/javascript">
        $(function () {
            var height = $("#divTotal").height();
            var master = $("#master").height();
            var content = parseFloat(height) - parseFloat(master) - 30;
            $("#tbList").css("height", content);
        });
    </script>
    <script type="text/javascript">
        $(function () {
            //   $('#btnModify').linkbutton('disable');
            $("#tbList").datagrid({
                url: '/Logic/BD/CompanyAjax.aspx?method=GetCompanyList',
                loadMsg: '数据加载中请稍后……',
                fitColumns: false,
                pagination: true,
                queryParams: com.serializeSearchArray("form1"),
                rownumbers: true,
                idField: "ID",
                singleSelect: true,
                pageSize: 20,
                pageList: [20, 50, 100],
                striped: true,
                frozenColumns: [[{ field: 'ck', checkbox: true, width: 30 },
                 { field: 'ID', title: 'ID', align: "center" ,width: 40},
                 {
                     field: 'ComName', title: '客户名称 ', align: "center", width: 160, editor: {
                         type: "validatebox",
                         options: {
                             required: true
                         }
                     }
                 },
                 {
                     field: 'SimplifiedCode', title: '客户简称', align: "center", width: 100, editor: {
                         type: "validatebox",
                         options: {}
                     }
                 } ]],
                columns: [[
                 {
                     field: 'ComAddress', title: '客户地址', align: "center", width:200, editor: {
                         type: "validatebox",
                         options: {}
                     }
                 },
                 {
                     field: 'Person', title: '客户联系人', align: "center", width: 100, editor: {
                         type: "validatebox",
                         options: {}
                     }
                 },
                 {
                     field: 'Phone', title: '客户联系固话', align: "center", width: 100, editor: {
                         type: "validatebox",
                         options: {}
                     }
                 },
                 {
                     field: 'MobilePhone', title: '联系手机号', align: "center", width: 100, editor: {
                         type: "validatebox",
                         options: {}
                     }
                 },
                 {
                     field: 'TaxpayerID', title: '纳税人识别号', align: "center", width: 100, editor: {
                         type: "validatebox",
                         options: {}
                     }
                 },
                 {
                     field: 'Bank', title: '开户银行', align: "center", width: 100, editor: {
                         type: "validatebox",
                         options: {}
                     }
                 },
                 {
                     field: 'BankAccount', title: '银行账号', align: "center", width: 100, editor: {
                         type: "validatebox",
                         options: {}
                     }
                 },
                 {
                     field: 'PostCode', title: '邮编', align: "center", width: 100, editor: {
                         type: "validatebox",
                         options: {}
                     }
                 },
                 {
                     field: 'Fax', title: '传真', align: "center", width: 100, editor: {
                         type: "validatebox",
                         options: {}
                     }
                 },
                 {
                     field: 'Mail', title: '客户邮箱', align: "center", width: 100, editor: {
                         type: "validatebox",
                         options: {}
                     }
                 },
                
                 
                {
                    field: 'Note', title: '备注', align: "center", width: 100, editor: {
                        type: "validatebox",
                        options: {}
                    }
                 }]],
                onAfterEdit: function (rowIndex, rowData, changes) {
                    if (editAction == "edit") {
                        com.ajax({
                            url: "/Logic/BD/CompanyAjax.aspx?method=EditCompany",
                            data: rowData,
                            success: function (data) {
                                com.message(data.state, data.msg, function () { $("#tbList").datagrid("reload"); });
                            }
                        });
                    } else if (editAction == "add") {
                        com.ajax({
                            url: "/Logic/BD/CompanyAjax.aspx?method=AddCompany",
                            data: rowData,
                            success: function (data) {
                                com.message(data.state, data.msg, function () { $("#tbList").datagrid("reload"); });
                            }
                        });
                    }
                    editRow = undefined;
                },
                onCancelEdit: function (rowIndex, rowData) {
                    $("#tbList").datagrid("rejectChanges");
                }
            });
        });

    </script>
    <script type="text/javascript">
        editRow = undefined;
        editAction = undefined;

        //添加
        function funcAdd() {
            //添加时如果没有正在编辑的行，则在datagrid的第一行插入一行
            if (editRow == undefined) {
                $("#tbList").datagrid("insertRow", {
                    index: 0,
                    row: {}
                });
                //将新插入的那一行开户编辑状态
                $("#tbList").datagrid("beginEdit", 0);
                //给当前编辑的行赋值
                editRow = 0;
                editAction = "add";
            }
        }

        //编辑
        function funcEdit() {
            var row = $('#tbList').datagrid('getSelected');

            if (row) {
                if (editRow != undefined) {
                }
                else {
                    var index = $("#tbList").datagrid('getRowIndex', row);
                    $("#tbList").datagrid('beginEdit', index);
                    editAction = "edit";
                    editRow = index;
                    rowData = $("#tbList").datagrid("getSelected");
                }
            }
            else {
                com.message("information", "请选中一行");
            }
        }

        //查询
        function funcSearch() {
            var para = com.serializeSearchArray("form1");
            $("#tbList").datagrid("load", para);
            editRow = undefined;
            editAction = undefined;
        }

        //删除
        function funcRemove() {
            $.messager.confirm('确认对话框', '您确定删除该客户吗？', function (r) {
                if (r) {
                    var row = $('#tbList').datagrid('getSelected');
                    if (row) {
                        com.ajax({
                            url: "/Logic/BD/CompanyAjax.aspx?method=DelCompany",
                            data: { ID: row.ID },
                            success: function (data) {
                                com.message(data.state, data.msg, function () { $("#tbList").datagrid("reload"); $('#tbList').datagrid('clearSelections'); })
                            }
                        });
                    }
                    else {
                        com.message("information", "请选中一行");
                    }
                }
            });
            editRow = undefined;
            editAction = undefined;
        }

        //取消编辑
        function funcCancel() {
            $('#tbList').datagrid("cancelEdit", editRow);
            editRow = undefined;
            editAction = undefined;
        }

        //重置
        function funcReload() {
            $("#form1").form("reset");
            var para = com.serializeSearchArray("form1");
            $("#tbList").datagrid("load", para);
            editRow = undefined;
            editAction = undefined;
        }

        function funcSave() {
            $('#tbList').datagrid('endEdit', editRow);
        }

        function funcAddContact() {
            var row = $('#tbList').datagrid('getSelected');
            if (row) {
                top.wrapper.addTab("添加客户联系人", "/UI/BD/CompanyContact.aspx?Id=" + row.ID);
            }
            else {
                com.message("information", "请选中一行");
            }
        }

        function funcAddAddress() {
            var row = $('#tbList').datagrid('getSelected');
            if (row) {
                top.wrapper.addTab("添加客户地址", "/UI/BD/CompanyAddress.aspx?Id=" + row.ID);
            }
            else {
                com.message("information", "请选中一行");
            }
        }

        //导出 todo
        function funcExportExcel() {
            //var para = com.serializeSearchArray1("form1");
            //top.wrapper.addTab("导出", "/Export.aspx?Type=0&TableId=84&searchData=" + JSON.stringify(para));
            //$("#tbList").datagrid("unselectAll");
        }
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <div id="divTotal" style="height: 100%; width: 100%">

        <div id="master" class="container_12" style="height: auto">
            <form id="form1">
                <div class="grid_1 sealbl" style="text-align: right;">
                    客户名称 :
                </div>
                <div class="grid_2 seaval" style="text-align: left;">
                    <input type="text" id="ComName" name="ComName" data-cp="co" />
                </div>
                <div class="grid_1 sealbl" style="text-align: right;">
                    客户地址 :
                </div>
                <div class="grid_2 seaval" style="text-align: left;">
                    <input type="text" id="ComAddress" name="ComAddress" data-cp="co" />
                </div>
                <div class="grid_1 sealbl" style="text-align: right;">
                    客户简称 :
                </div>
                <div class="grid_2 seaval" style="text-align: left;">
                    <input type="text" id="SimplifiedCode" name="SimplifiedCode" data-cp="co" />
                </div>
            </form>
        </div>
        <table id="tbList" title="客户信息表 " style="width: 100%">
        </table>
        <div id="assignCompanyDiv">
        </div>
    </div>
</asp:Content>
